ct_abbrev <-
function(data) {
    data <- gsub('[[:blank:]]|[[:digit:]]|[[:punct:]]', '', x = data)
    data <- toupper(data)
    abbrev <- substr(data, 1, 3)

    if (any(duplicated(abbrev))) {
        dup <- duplicated(abbrev) | duplicated(abbrev, fromLast = TRUE)

        n <- max(nchar(data[dup]))
        o <- length(dup[dup == TRUE])

        for (i in 4:n) {
            replace <- substr(data[dup], i, i)

            if (! any(duplicated(replace))) {
                for (j in 1:o) {
                    abbrev[dup][j] <- sub('.$', replace[j], abbrev[dup][j])
                }

                break
            }
        }
    }

    if (any(duplicated(abbrev))) {
        warning('Failed to make abbreviations unique.')
    }

    return(abbrev)
}
